home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / wbcalib.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  13KB  |  472 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        wbcalib.c
  13.  * Purpose:     requester to set calibration & quantization parameters
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     23-April-1994 CPP; Created.
  16.  *              4-Aug-94 CPP (1.04); Filenames may contain spaces
  17.  *              4-Aug-94 CPP (1.04); Allow full size pathnames here
  18.  *              5-Aug-94 CPP (1.05); Show total calibrations in effect
  19.  *              6-Aug-94 CPP (1.10); Minor interface improvements
  20.  *              14-Dec-94 CPP (1.17); Fix button gadgets for >4 colors
  21.  *              10-Feb-95 CPP (1.37); Use progress requesters
  22.  *
  23.  * Comments:    Workbench GUI.  Amiga Dependent!
  24.  */
  25.  
  26. #ifdef AMIGA  /* This module is AMIGA dependent */
  27.  
  28. #include <stdio.h>     /* sprintf() */
  29. #include <string.h>
  30.  
  31. /*
  32.  * Amiga includes
  33.  */
  34. #include <exec/types.h>
  35. #include <workbench/workbench.h>
  36. #include <intuition/intuition.h>
  37. #include <clib/intuition_protos.h>
  38. #include <clib/exec_protos.h>
  39. #include <dos.h> /* chkabort() */
  40.  
  41. /*
  42.  * GFFT includes
  43.  */
  44. #include "gfft.h"
  45. #include "settings.h"  /* for testing */
  46. #include "wbench.h"
  47.  
  48. /*
  49.  * External globals
  50.  */
  51. extern struct Window *dialog_window_p;
  52. extern char *Processing_Calibration_S;
  53.  
  54. /*
  55.  * Local statics
  56.  */
  57. static char *calibration_filename = NULL;
  58.  
  59. static struct Requester *calibration_rp = NULL;
  60.  
  61. static struct Gadget *help_calibration_gadgetp;
  62. static struct Gadget *calibration_gadgetp;
  63. static struct Gadget *db_calibration_gadgetp;
  64. static struct Gadget *select_calibration_gadgetp;
  65. static struct Gadget *select_db_calibration_gadgetp;
  66. static struct Gadget *no_calibration_gadgetp;
  67. static struct Gadget *quantization_gadgetp;
  68. static struct Gadget *low_y_gadgetp;
  69. static struct Gadget *high_y_gadgetp;
  70. static struct Gadget *cancel_quantization_gadgetp;
  71. static struct Gadget *cancel_low_y_gadgetp;
  72. static struct Gadget *cancel_high_y_gadgetp;
  73. static struct Gadget *end_calibration_gadgetp;
  74. static struct Gadget *calibration_message_gadgetp;
  75.  
  76. static char message_string[80];
  77.  
  78. static void cal_proc_message (void);
  79.  
  80. static void cal_prog_begin (struct Gadget *cal_gadgetp, 
  81.                char *cal_func(char *arg));
  82.  
  83. static char *cal_prog_get_name (char *cal_filename);
  84.  
  85.  
  86. #define MAX_VAL_SIZE 30
  87.  
  88. #if FALSE  /* defeat this for now */
  89. #define ACTIVATE_CAL_CANCEL \
  90.     if (CalibrationList) \
  91.     { \
  92.     gadget__enable (no_calibration_gadgetp, \
  93.              dialog_window_p); \
  94.     } \
  95.     else \
  96.     { \
  97.     gadget__disable (no_calibration_gadgetp, \
  98.              dialog_window_p); \
  99.     }
  100. #else
  101. #define ACTIVATE_CAL_CANCEL
  102. #endif
  103.  
  104. void calibration_requester (void)
  105. {
  106.     struct IntuiMessage *message;
  107.     APTR *address = NULL;
  108.     ULONG class = 0;
  109.     UWORD qualifier = NULL;
  110.     APTR *next_address = NULL;
  111.     ULONG next_class = 0;
  112.     UWORD next_qualifier = NULL;
  113.     APTR string_gadget_being_set = NULL;
  114.     char string[MAX_VAL_SIZE];
  115.  
  116.     if (!calibration_rp)
  117.     {
  118.     gadget__begin (GTYP_REQGADGET);
  119. /*
  120.  * Setup Gadgets
  121.  */
  122.     help_calibration_gadgetp = action_button__new ("Help", 0, 0);
  123.  
  124.     string[0] = '\0';
  125.     calibration_gadgetp = string_gadget__new ("Calibration:",
  126.                         string,
  127.                         MAX_PATH,
  128.                         47, 0, 1);
  129.  
  130.     select_calibration_gadgetp = action_button__new ("S",49,1);
  131.  
  132.     db_calibration_gadgetp = string_gadget__new ("dB Calibration:",
  133.                            string,
  134.                            MAX_PATH,
  135.                            47, 0, 2);
  136.  
  137.     select_db_calibration_gadgetp = action_button__new ("S",49,2);
  138.  
  139.     if (Quantization != MIN_QUANTIZATION)
  140.     {
  141.         sprintf (string, "%g", Quantization);
  142.     }
  143.     quantization_gadgetp = string_gadget__new ("Quantization:",
  144.                            string,
  145.                            MAX_VAL_SIZE,
  146.                            40, 0, 3);
  147.     cancel_quantization_gadgetp = action_button__new ("Cancel", 43, 3);
  148.  
  149.     if (LowY != LOWEST_Y)
  150.     {
  151.         sprintf (string, "%g", LowY);
  152.     }
  153.     low_y_gadgetp = string_gadget__new ("Low Y:",
  154.                            string,
  155.                            MAX_VAL_SIZE,
  156.                            40, 0, 4);
  157.  
  158.     cancel_low_y_gadgetp = action_button__new ("Cancel", 43, 4);
  159.  
  160.     if (HighY != HIGHEST_Y)
  161.     {
  162.         sprintf (string, "%g", HighY);
  163.     }
  164.     high_y_gadgetp = string_gadget__new ("High Y:",
  165.                            string,
  166.                            MAX_VAL_SIZE,
  167.                            40, 0, 5);
  168.  
  169.     cancel_high_y_gadgetp = action_button__new ("Cancel", 43, 5);
  170.  
  171.     calibration_message_gadgetp = message_gadget__new (40, 0, 6);
  172.  
  173.     no_calibration_gadgetp = action_button__new
  174.       ("Cancel All Calibrations", 0, 7);
  175.  
  176.     end_calibration_gadgetp = tall_action_button__new 
  177.       ("...Done", 43, 7);
  178.  
  179.     calibration_rp = requester__new ();
  180.     calibration_rp->ReqGadget = end_calibration_gadgetp;
  181.     calibration_rp->ReqText =  NULL;
  182.  
  183.     } /* Ok, calibration_rp has been created */
  184.     
  185.  
  186.     if (requester__display (calibration_rp, dialog_window_p))
  187.     {
  188.     ACTIVATE_CAL_CANCEL;
  189.     ActivateGadget (calibration_gadgetp,
  190.             dialog_window_p,
  191.             calibration_rp);
  192.     while (TRUE)
  193.     {
  194.         sprintf (message_string, "%d Calibration(s) in effect", 
  195.              calibration_list__count (&CalibrationList));
  196.         message_gadget__write (calibration_message_gadgetp, 
  197.                    message_string, dialog_window_p);
  198.         Wait (1 << dialog_window_p->UserPort->mp_SigBit);
  199.         while (message = (struct IntuiMessage *) GetMsg 
  200.            (dialog_window_p->UserPort))
  201.         {
  202.         class = message->Class;
  203.         qualifier = message->Qualifier;
  204.         address = message->IAddress;
  205.         ReplyMsg ((struct Message *) message);
  206.             /*
  207.          * Finish unfinished string
  208.          */
  209.  
  210.         if (string_gadget_being_set &&
  211.             string_gadget_being_set != address)
  212.         {
  213.             next_address = address;
  214.             next_class = class;
  215.             next_qualifier = qualifier;
  216.             address = string_gadget_being_set;
  217.             class = IDCMP_GADGETUP;
  218.             qualifier = NULL;
  219.         }
  220.         string_gadget_being_set = NULL;
  221.  
  222.         while (address) /* once for previous string, then next */
  223.         {
  224.             CATCH_ERROR
  225.  
  226.             if (qualifier & IEQUALIFIER_CONTROL)
  227.             {
  228.             help_message ("Workbench Calibration Help");
  229.             }
  230.             /*
  231.          * Check for string GADGETDOWN
  232.          */
  233.             else if (class == IDCMP_GADGETDOWN && 
  234.             ((struct Gadget *) address)->GadgetType &
  235.             GTYP_STRGADGET)
  236.             {
  237.             string_gadget_being_set = address;
  238.             }
  239.             else if (address == (APTR) help_calibration_gadgetp)
  240.             {
  241.             help_message ("Workbench Calibration Help");
  242.             }
  243.             else if (address == (APTR) end_calibration_gadgetp)
  244.             {
  245.             requester__remove (calibration_rp, dialog_window_p);
  246.             return;
  247.             }
  248.             else if (address == (APTR) no_calibration_gadgetp)
  249.             {
  250.             if (CalibrationList)
  251.             {
  252.                 set_no_calibrations (NullString);
  253.                 string_gadget__reset (calibration_gadgetp,
  254.                           "\0", dialog_window_p);
  255.                 string_gadget__reset (db_calibration_gadgetp,
  256.                           "\0", dialog_window_p);
  257.                 ACTIVATE_CAL_CANCEL;
  258.             }
  259.             }
  260.             else if (address == (APTR) cancel_quantization_gadgetp)
  261.             {
  262.             set_quantization (NullString);
  263.             string_gadget__reset (quantization_gadgetp,
  264.                           "\0", dialog_window_p);
  265.             }
  266.             else if (address == (APTR) cancel_low_y_gadgetp)
  267.             {
  268.             set_low_y (NullString);
  269.             string_gadget__reset (low_y_gadgetp,
  270.                           "\0", dialog_window_p);
  271.             }
  272.             else if (address == (APTR) cancel_high_y_gadgetp)
  273.             {
  274.             set_high_y (NullString);
  275.             string_gadget__reset (high_y_gadgetp,
  276.                           "\0", dialog_window_p);
  277.             }
  278.             else if (address == (APTR) calibration_gadgetp)
  279.             {
  280.             struct StringInfo *sinfop =
  281.               calibration_gadgetp->SpecialInfo;
  282.             char *buffer = sinfop->Buffer;
  283.             WORD *bpos = &sinfop->BufferPos;
  284.             if (strlen (buffer) && *bpos > 0)
  285.             {
  286.                 cal_prog_begin (calibration_gadgetp,
  287.                         set_calibration);
  288.                 ACTIVATE_CAL_CANCEL;
  289.                 *bpos = 0;
  290.                 refresh_gadget (calibration_gadgetp,
  291.                         dialog_window_p);
  292.             }
  293.             if (!next_address)
  294.             {
  295.                 ActivateGadget (db_calibration_gadgetp,
  296.                         dialog_window_p,
  297.                         calibration_rp);
  298.             }
  299.             }
  300.             else if (address == (APTR) select_calibration_gadgetp)
  301.             {
  302.             char *calibration_file = file_requestor
  303.               ("Select Calibration File");
  304.             if (calibration_file)
  305.             {
  306.                 struct StringInfo *sinfop =
  307.                   calibration_gadgetp->SpecialInfo;
  308.                 WORD *bpos = &sinfop->BufferPos;
  309.  
  310.                 string_gadget__reset (calibration_gadgetp,
  311.                           calibration_file,
  312.                           dialog_window_p);
  313.                 cal_prog_begin (calibration_gadgetp,
  314.                         set_calibration);
  315.  
  316.                 ACTIVATE_CAL_CANCEL;
  317.                 *bpos = 0;
  318.                 refresh_gadget (calibration_gadgetp,
  319.                         dialog_window_p);
  320.             }
  321.             if (!next_address)
  322.             {
  323.                 ActivateGadget (calibration_gadgetp,
  324.                         dialog_window_p,
  325.                         calibration_rp);
  326.             }
  327.             }
  328.             else if (address == (APTR) db_calibration_gadgetp)
  329.             {
  330.             struct StringInfo *sinfop =
  331.               db_calibration_gadgetp->SpecialInfo;
  332.             char *buffer = sinfop->Buffer;
  333.             WORD *bpos = &sinfop->BufferPos;
  334.             if (strlen (buffer) && *bpos > 0)
  335.             {
  336.                 cal_prog_begin (db_calibration_gadgetp,
  337.                         set_db_calibration);
  338.                 ACTIVATE_CAL_CANCEL;
  339.                 *bpos = 0;
  340.                 refresh_gadget (calibration_gadgetp,
  341.                         dialog_window_p);
  342.             }
  343.             if (!next_address)
  344.             {
  345.                 ActivateGadget (quantization_gadgetp,
  346.                         dialog_window_p,
  347.                         calibration_rp);
  348.             }
  349.             }
  350.             else if (address == (APTR) 
  351.                  select_db_calibration_gadgetp)
  352.             {
  353.             char *db_calibration_file = file_requestor
  354.               ("Select dB Calibration File");
  355.             if (db_calibration_file)
  356.             {
  357.                 struct StringInfo *sinfop =
  358.                   db_calibration_gadgetp->SpecialInfo;
  359.                 WORD *bpos = &sinfop->BufferPos;
  360.  
  361.                 string_gadget__reset (db_calibration_gadgetp,
  362.                           db_calibration_file,
  363.                           dialog_window_p);
  364.                 cal_prog_begin (db_calibration_gadgetp,
  365.                         set_db_calibration);
  366.                 ACTIVATE_CAL_CANCEL;
  367.                 *bpos = 0;
  368.                 refresh_gadget (db_calibration_gadgetp,
  369.                         dialog_window_p);
  370.             }
  371.             if (!next_address)
  372.             {
  373.                 ActivateGadget (db_calibration_gadgetp,
  374.                         dialog_window_p,
  375.                         calibration_rp);
  376.             }
  377.             }
  378.             else if (address == (APTR) quantization_gadgetp)
  379.             {
  380.             string_gadget__apply (quantization_gadgetp, 
  381.                           set_quantization);
  382.             if (Quantization == MIN_QUANTIZATION)
  383.             {
  384.                 struct StringInfo *sinfop =
  385.                   quantization_gadgetp->SpecialInfo;
  386.                 char *buffer = sinfop->Buffer;
  387.                 buffer[0] = '\0';
  388.                 refresh_gadget (quantization_gadgetp,
  389.                         dialog_window_p);
  390.             }
  391.             if (!next_address)
  392.             {
  393.                 ActivateGadget (low_y_gadgetp,
  394.                         dialog_window_p,
  395.                         calibration_rp);
  396.             }
  397.             }
  398.             else if (address == (APTR) low_y_gadgetp)
  399.             {
  400.             string_gadget__apply (low_y_gadgetp, 
  401.                           set_low_y);
  402.             if (!next_address)
  403.             {
  404.                 ActivateGadget (high_y_gadgetp,
  405.                         dialog_window_p,
  406.                         calibration_rp);
  407.             }
  408.             }
  409.             else if (address == (APTR) high_y_gadgetp)
  410.             {
  411.             string_gadget__apply (high_y_gadgetp, 
  412.                           set_high_y);
  413.             if (!next_address)
  414.             {
  415.                 ActivateGadget (calibration_gadgetp,
  416.                         dialog_window_p,
  417.                         calibration_rp);
  418.             }
  419.             }
  420.             END_CATCH_ERROR;
  421.             address = next_address;
  422.             class = next_class;
  423.             qualifier = next_qualifier;
  424.             next_address = NULL;
  425.             next_class = NULL;
  426.             next_qualifier = NULL;
  427.         } /* while next address */
  428.         }
  429.     }
  430.     }
  431. }
  432.  
  433. static void cal_proc_message (void)
  434. {
  435.     sprintf (message_string, Processing_Calibration_S);
  436.     message_gadget__write (calibration_message_gadgetp, 
  437.                message_string, dialog_window_p);
  438. }
  439.  
  440. static void cal_prog_begin (struct Gadget *cal_gadgetp, 
  441.                 char *cal_func(char *arg))
  442. {
  443.     static struct Requester *cal_progress_rp = NULL;
  444.  
  445.     cal_proc_message ();
  446.  
  447.     if (!cal_progress_rp)
  448.       cal_progress_rp = progress_requester__new
  449.       (Processing_Calibration_S, 35);
  450.  
  451.     name_string_gadget__apply (cal_gadgetp, cal_prog_get_name);
  452.  
  453.     progress_requester__apply (cal_progress_rp,
  454.                    cal_func,
  455.                    calibration_filename,
  456.                    dialog_window_p);
  457. }    
  458.  
  459. static char *cal_prog_get_name (char *cal_filename)
  460. {
  461.     calibration_filename = cal_filename;
  462.     return cal_filename;
  463. }
  464.  
  465.  
  466.  
  467. #endif /* end ifdef AMIGA */
  468.  
  469.  
  470.  
  471.  
  472.